<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>17.super原理分析s</title>
</head>

<body>

</body>
<script>
  class User {
    show () {
      console.log(this.name);
    }
  }
  class Admin extends User {
    constructor(name) {
      super();
      this.name = name;
    }
    show () {
      super.show(); //打印 user show
    }
  }

  let admin = new Admin('后盾人');
  admin.show(); //user show admin show

  // super 原理
  let hd = {
    name: 'hd.name',
    show () {
      console.log(this.name);
    }
  }

  let xj = {
    __proto__: hd,
    name: 'xj.name',
    show () {
      //直接调用 原型 的show方法 ，this 指向原型，name打印为hd.name
      // 需要用call方法将原型this指向子类
      this.__proto__.show();//hd.name 
      this.__proto__.show.call(this); // xj.name
    }
  }
  xj.show();// hd.name  xj.name

</script>

</html>